package com.vp.org.dao.impl;

import com.vp.org.constant.UserSql;
import com.vp.org.dao.UserDao;
import com.vp.org.pojo.UserInfo;
import com.vp.org.util.JdbcUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;

@SuppressWarnings("unused")
public class UserDaoImpl extends JdbcUtil implements UserDao, UserSql {

    @Override
    public int add(UserInfo info) {
        return template.update(ADD_USER, info.getPhone(), info.getPassword(),
                info.getEmail(), info.getQq(), info.getNickname(), info.getAddress(),
                info.getSchool(), info.getGrade(), info.getClassname(),
                info.getProvince(), info.getCity(), info.getDistrict());
    }

    @Override
    public int update(UserInfo info) {
        return template.update(UPDATE_USER, info.getType(), info.getUsername(),
                info.getGender(), info.getEmail(), info.getQq(),
                info.getSchool(), info.getClassname(), info.getBirthday(),
                info.getHobby(), info.getIntroduce(), info.getPicture(),
                info.getUserId());
    }

    @Override
    public int delete(UserInfo info) {
        return 0;
    }

    @Override
    public int queryByPhone(UserInfo info) {
        return template.queryForList(CHECK_PHONE, info.getPhone()).size();
    }

    @Override
    public int checkForInfo(UserInfo info) {
        return template.queryForList(CHECK_USER, info.getPhone(), info.getPassword()).size();
    }

    @Override
    public UserInfo queryForInfo(UserInfo info) {
        return template.queryForObject(Login_USER,
                new BeanPropertyRowMapper<>(UserInfo.class),
                info.getPhone(), info.getPassword());
    }

    @Override
    public List<UserInfo> queryAll() {
        return null;
    }
}
